<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false"%>
<%@ include file="/common/backcommon.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>Breaking Fast</title>
		<script type="text/javascript">
			function updateOperate(id, status) {
				$.ajax({
					url: "${base}/backOrderCtl/updateStatus",
					type: "post",
					data: {orderId : id, status : status},
					success: function(result){
						if(true == result) {
							var pageNumber = $("#pageNumber").val();
							onPageChange(pageNumber);
							alert("处理成功！");
						}
					}
				});
			};
			
			function detailOperate(id) {
				location.href = "${base}/backOrderCtl/backDetail?orderId=" + id;
			};
			
			function dishInfo(id) {
				location.href = "${base}/backOrderCtl/toInfo?orderId=" + id;
			};
			
	        function loadPage(totalCount, pageSize, pageCurrent) {
		        $("#page").smartpaginator({
                    totalrecords: totalCount, 
                    recordsperpage: pageSize, 
                    initval: pageCurrent,  
                    next: '下一页', 
                    prev: '上一页', 
                    first: '第一页', 
                    last: '最后一页', 
                    theme: 'black', 
                    go: 'Go',
                    onchange: onPageChange
				});
	        };
			
			function onPageChange(newPageValue) {
				//获取查询参数
				var priceMax = $("#priceMax").val();
				var priceMin = $("#priceMin").val();
				var startCreateDate = $("#startCreateDate").val();
				var endCreateDate = $("#endCreateDate").val();
				var status = $("#status").val();
				var params = {
					priceMax : priceMax,
					priceMin : priceMin,
					startCreateDate : startCreateDate,
					endCreateDate : endCreateDate,
					status : status,
					pageNumber : newPageValue
				};
				var dataTr = $("#pageList tr");
				for(var i = 0; i < dataTr.length; i++) {
					if(i != 0) {
						$(dataTr[i]).remove();
					}
				}
				$.ajax({
					url: "${base}/backOrderCtl/select",
					type: "post",
					data: params,
					success: function(result){
						var dataTable = $("#pageList");
						for(var i = 0; i < result.resultList.length; i++) {
							var trClassName = ""; 
							if(i%2 == 0){
								trClassName = "list_tab_left";
							}
							var orderid = result.resultList[i].orderid;
							var servicedate = result.resultList[i].servicedateStr;
							var servicetime = result.resultList[i].servicetimeStr;
							var site = result.resultList[i].site;
							var totalprice = result.resultList[i].totalprice;
							var username = result.resultList[i].username;
							var customername = "";
							if(null != result.resultList[i].customer) {
								customername = result.resultList[i].customer.username;
							}
							var phone = result.resultList[i].phone;
							var email = result.resultList[i].email;
							var contact = result.resultList[i].contactStr;
							var status = result.resultList[i].status;
							var createdate = result.resultList[i].createdateStr;
							var statusInfo;
							if(0 == status) {
								statusInfo = "未处理";
							} else if(1 == status) {
								statusInfo = "已处理";
							}
							var row = $("<tr class='" + trClassName + "'><td style='height:40px;width:200px;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;'>" + site + "</td>" +
								"<td>" + totalprice + "</td><td>" + username + "</td><td>" + customername + "</td><td>" + phone + "</td><td>" + email + "</td>" +
								"<td>" + statusInfo + "</td><td>" + createdate + "</td><td>" + (0 == status ?"<a href='#' onclick='updateOperate(\"" +orderid +"\", 1)'>处理</a>&nbsp;&nbsp;" : "") + 
								"<a href='#' onclick='detailOperate(\"" +orderid +"\")'>详情</a>&nbsp;&nbsp;" + 
								"<a href='#' onclick='dishInfo(\"" +orderid +"\")'>菜品</a></td></tr>");
							dataTable.append(row);
						}
						$("#pageList tr:even").addClass("bg_color");
						loadPage(result.totalCount, result.pageSize, result.pageCurrent);
					}
				});
			};
			
			$(function() {
				onPageChange(1);
				
				$("#queryBtn").bind("click",function(){
					if($.formValidator.pageIsValid("1")) {
						var pageNumber = $("#pageNumber").val();
						onPageChange(pageNumber);
					}
				});
				
				//验证信息
				$.formValidator.initConfig({
					formID: "queryForm",
					debug:false,
					onError: function(msg, obj, errorlist){
					}
				});
				$("#priceMin").formValidator({empty:true, tipID:"priceMinTip", onShow: "请输入数字", onCorrect: "" }).inputValidator({min:0, max:9999, type:"value", onErrorMin:"你输入的值必须大于等于0", onError:"单价必须在0-9999之间，请确认"}).compareValidator({desEmpty:true, desID:"priceMax", dataType:"number", operateor:"<=", onError:"开始单价不能大于结束价格"}).defaultPassed();
				$("#priceMax").formValidator({empty:true, tipID:"priceMaxTip", onShow: "请输入数字", onCorrect: "" }).inputValidator({min:0, max:9999, type:"value", onErrorMin:"你输入的值必须大于等于0", onError:"单价必须在0-9999之间，请确认"}).compareValidator({desEmpty:true, desID:"priceMin", dataType:"number", operateor:">=", onError:"结束单价不能小于开始价格"}).defaultPassed();
			});
		</script>
	</head>
	
	<body>
		<div class="cms_right">
		  	<div class="cms_title">
		    	<span>订单管理：</span>
		    </div>
			    <div class="cms_search">
	    			<form id="queryForm" >
						<table width="1000" border="0" class="search_bd">
							<tr>
					            <td class="yh_name">开始价格：</td>
					            <td class="yh_bd"><input type="text" id="priceMin" class="cms_text02" maxlength="3"/></td>
					            <td class="tishi"><div id="priceMinTip" style="width:200px"></div></td>
					            <td class="yh_name">结束单价：</td>
					            <td class="yh_bd"><input type="text" id="priceMax" class="cms_text02" maxlength="3"/></td>
					            <td><div id="priceMaxTip" style="width:200px"></div></td>
							</tr>
							<tr>
								<td class="yh_name">下单开始时间：</td>
								<td class="yh_bd"><input type="text" id="startCreateDate" class="Wdate" style="cursor: pointer" onFocus="WdatePicker({readOnly:true,dateFmt:'yyyy-MM-dd HH:mm',maxDate:'#F{$dp.$D(\'endCreateDate\')}'})"/></td>
								<td class="tishi"><div id="startCreateDateTip" style="width:200px"></div></td>
								<td class="yh_name">下单结束时间：</td>
								<td class="yh_bd"><input type="text" id="endCreateDate" class="Wdate" style="cursor: pointer" onFocus="WdatePicker({readOnly:true,dateFmt:'yyyy-MM-dd HH:mm',minDate:'#F{$dp.$D(\'startCreateDate\')}'})"/></td>
								<td><div id="endCreateDateTip" style="width:200px"></div></td>
							</tr>
							<tr>
								<td class="yh_name">状态：</td>
								<td class="yh_bd">
						            <select id="status" class="cms_text02" >
						            	<option value="" selected="selected">=请选择=</option>
						            	<option value="0">未处理</option>
						            	<option value="1">已处理</option>
						            </select>
								</td>
								<td class="tishi"><div id="statusTip" style="width:200px"></div></td>
								<td></td>
								<td></td>
								<td></td>
							</tr>
							<tr>
								<td></td>
								<td align="right"><input type="reset" class="search_btn" value="重置" /></td>
								<td align="center" ><input type="button" id="queryBtn" class="search_btn" value="搜索" /></td>
								<td></td>
								<td></td>
								<td></td>
							</tr>
				        </table>
		   			</form>
			    </div>
			<div class="grid-view">
				<table id="pageList" class="items" width="100%" border="1" cellspacing="0" cellpadding="0">
					<tr class="list_tab_title">
						<td bgcolor="#eae9eb">送餐地址</td>
						<td bgcolor="#eae9eb">价格</td>
						<td bgcolor="#eae9eb">收货人</td>
						<td bgcolor="#eae9eb">订餐人</td>
						<td bgcolor="#eae9eb">联系电话</td>
						<td bgcolor="#eae9eb">邮箱</td>
						<td bgcolor="#eae9eb">状态</td>
						<td bgcolor="#eae9eb">下单时间</td>
						<td bgcolor="#eae9eb">操作</td>
					</tr>
				</table>
				<div id="page" style="margin: auto;"></div>
			</div>
		</div>
	</body>
</html>
	